<?php
class PNProvinceArray extends PNObjectExArray {
  function PNProvinceArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'votedatacenter_province';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_init($init, $where);
  }

  function genSort(){
    $pntables = pnDBGetTables();
    $column = $pntables[$this->_objType.'_column'];

    $desc  = FormUtil::getPassedValue ('desc', null, 'GET');
    $asc  = FormUtil::getPassedValue ('asc', null, 'GET');

    if(isset($desc)){
      //return " ORDER BY $column[$desc] desc";
      return " ORDER BY CONVERT( $column[$desc] USING tis620 ) desc";
    }
    if(isset($asc)){
      //return " ORDER BY $column[$asc] asc";
      return " ORDER BY CONVERT( $column[$asc] USING tis620 ) asc";
    }
  }
  
  function genFilter(){
    $pntables = pnDBGetTables();
    $column  = $pntables[$this->_objType.'_column'];
    
    $id  = FormUtil::getPassedValue ('id', null, 'GET');
    $list  = FormUtil::getPassedValue ('list', null , 'GET');
    
    $wheres = array();
    if(isset($list)){
      $wheres[] = " $column[id] IN (".$list.")";
    }
    if ($id && intval($id)){
      $wheres[] = " $column[id] = ".$id;
    }

      return implode(' AND ', $wheres);

    
  }
}
